//
//  ViewController.m
//  28-UIViewAnimation2
//
//  Created by Snow on 16/8/22.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"

@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIButton *animationbutton;
@property (nonatomic, strong) UIButton *animationButton2;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.animationbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    _animationbutton.frame = CGRectMake(100, 100, 200, 200);
    [self.view addSubview:_animationbutton];
    self.animationbutton.backgroundColor = [UIColor cyanColor];
    [_animationbutton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    _animationView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_animationView];
    
    self.animationButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _animationButton2.frame = CGRectMake(100, 400, 200, 200);
    [self.view addSubview:_animationbutton];
    self.animationButton2.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.animationButton2];
    [_animationButton2 addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    
    // 参数1:
    // 参数2:
    // 参数3: 0.0 ~ 1.0 数值越小, 阻力越小, 数值越大, 阻力越大
    // 参数4: 速度
    // 参数5: 选项
    [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:15.0f options:UIViewAnimationOptionCurveLinear animations:^{
        _animationView.x_width = 100;
        _animationView.x_height = 300;
        _animationView.backgroundColor = [UIColor yellowColor];
    } completion:^(BOOL finished) {

    }];
}
- (void)button:(UIButton *)button
{
    //参数1: 需要执行动画的view
    //参数2: 持续时间
    //参数3: 动画效果
//    [UIView transitionWithView:_animationbutton duration:5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//    _animationbutton.x_height = 100;
//} completion:^(BOOL finished) {
//    //动画可以嵌套动画
//    [UIView animateWithDuration:0.5 animations:^{
//        _animationbutton.x_height = 200;
//    }];
//}];
    [UIView transitionFromView:_animationbutton toView:_animationButton2
 duration:3 options:UIViewAnimationOptionCurveLinear completion:^(BOOL finished) {
    }];
}
- (void)viewDidAppear:(BOOL)animated
{

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
